<?php

namespace app\api\controller\logistics;

use app\common\controller\Api;
use think\Exception;
use think\Request;

class Address extends Api
{
    public $noNeedRight = "*";

    public $service;

    public function __construct()
    {
        parent::__construct();
        $this->service= new \app\common\service\logistics\Address();
    }

    /**
     * 操作取件or收件地址
     * @param Request $request
     * @return void
     */
    public function create_add(Request $request)
    {
        if(!$this->request->isPost()){
            $this->error("非法请求");
        }
        try {
            $res = $this->service->Add($this->auth->id,$request);
            $this->success("操作成功",$res);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 删除地址
     * @return void
     */
    public function add_del()
    {
        try {
            $res = $this->service->del_address($this->request->param("id"));
            $this->success("操作成功",$res);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 地址列表
     * @return void
     */
    public function add_list()
    {

        try {
            $res = $this->service->add_list($this->auth->id);
            $this->success("操作成功",$res);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

    /**
     * 地址列表
     * @return void
     */
    public function address_info(Request $request)
    {

        try {
            $res = $this->service->address_info($this->auth->id,$request);
            $this->success("操作成功",$res);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }
}